﻿using System.Windows;
using System.Windows.Controls;

using Gonte.Wpf.Controls.ViewModel;
using Gonte.Wpf.Controls.ViewModel.Commands;

using MyWpfControlsTestBench.Model;

namespace MyWpfControlsTestBench.Demos
{
    public partial class TreeViewControlDemoWindow 
        : Window
    {
        public TreeViewControlDemoWindow()
        {
            InitializeComponent();

            // Create the model
            RootTreeItem rootItem = new RootTreeItem();
            rootItem.Name = "Custom Root";

            for (int i = 0; i < 20; ++i)
            {
                ChildTreeItem childItem = new ChildTreeItem();
                childItem.Name = "Custom Child " + (i + 1).ToString();

               rootItem.Children.Add(childItem);
            }

            ContentObjectViewModelInfo viewModelInfo = (ContentObjectViewModelInfo)ContentObjectViewModelInfo.GetInfo(typeof(RootTreeItem));
            // Create the view model
            ContentObjectViewModel viewModel = new ContentObjectViewModel(viewModelInfo, null, rootItem);

            viewModel.SelectionChanged += delegate(object sender, ViewModelEventArgs args)
            {
                MessageBox.Show(string.Format("Selected object: '{0}'", args.ViewModel.Model.ToString()));
            };

            
            viewModelInfo.ContextMenuFactory = delegate(object @object)
            {
                ContextMenu contextMenu = new ContextMenu();
                ViewModelBase.AddMenuItem(contextMenu, "Add a root", ViewModelCommands.AddChild);
                return contextMenu;
            };

            DataContext = demoTreeControl.ViewModel = viewModel;
        }
    }
}
